<template>
	<view class="container">
		<view class="example">
			<uni-forms ref="form" :model="shbl" label-width="100px" >
				<uni-forms-item label="病灶（cm）" name="bcBzCd">
					<uni-row class="demo-uni-row">
						<uni-col :span="6">
							<uni-easyinput :disabled="isDisabled" v-model="shbl.bcBzCd" type="digit"  @change="autoSaven" placeholder="请输入大小（cm）" />
						</uni-col>
						<uni-col :span="3" class="wbkx">x</uni-col>
						<uni-col :span="6">
							<uni-easyinput :disabled="isDisabled" v-model="shbl.bcBzKd" type="digit"  @change="autoSaven" placeholder="请输入大小（cm）" />
						</uni-col>
						<uni-col :span="3" class="wbkx">x</uni-col>
						<uni-col :span="6">
							<uni-easyinput :disabled="isDisabled" v-model="shbl.bcBzGd" type="digit"  @change="autoSaven" placeholder="请输入大小（cm）" />
						</uni-col>
					</uni-row>
				</uni-forms-item>
				<uni-forms-item label="病理学类型" name="blxlx">
					<uni-easyinput :disabled="isDisabled" v-model="shbl.blxlx"  @change="autoSaven" placeholder="请输入病理学类型" />
				</uni-forms-item>
				<uni-forms-item label="组织学评分" name="zzxfj">
					<uni-easyinput :disabled="isDisabled" v-model="shbl.zzxfj"  @change="autoSaven" placeholder="请输入组织学评分" />
				</uni-forms-item>
				<uni-forms-item label="ER百分比" name="blEr">
					<uni-easyinput :disabled="isDisabled" v-model="shbl.blEr"  @change="autoSaven" placeholder="请输入ER百分比" />
				</uni-forms-item>
				<uni-forms-item label="PR百分比" name="blPr">
					<uni-easyinput :disabled="isDisabled" v-model="shbl.blPr"  @change="autoSaven" placeholder="请输入PR百分比" />
				</uni-forms-item>
				<uni-forms-item label="Ki-67百分比" name="blKi">
					<uni-easyinput :disabled="isDisabled" v-model="shbl.blKi"  @change="autoSaven" placeholder="请输入Ki-67百分比" />
				</uni-forms-item>
				<uni-forms-item label="Her2" name="blHer">
					<uni-data-select
					      :disabled="isDisabled" v-model="shbl.blHer"
					      :localdata="her2DictList"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="FISH" name="blFish">
					<uni-data-select
					      :disabled="isDisabled" v-model="shbl.blFish"
					      :localdata="fishDictList"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="分子分型" name="fzfx">
					<uni-data-select
					      :disabled="isDisabled" v-model="shbl.fzfx"
					      :localdata="fzfxDictList"></uni-data-select>
				</uni-forms-item>
			
				
				<uni-forms-item label="前哨淋巴结活检" name="qslbj">
					<uni-data-checkbox :disabled="isDisabled" v-model="shbl.qslbj" @change="ycxsChange($event,'qslbjSzcdShow',['qslbjSzcd','qslbjSzkd'])" :localdata="dictSf" />
				</uni-forms-item>
				
				<uni-row class="demo-uni-row" v-show="qslbjSzcdShow">
					<uni-col :span="11">
						<uni-forms-item label="活检数目" name="qslbjSzcd">
							<uni-easyinput :disabled="isDisabled" v-model="shbl.qslbjSzcd" type="digit"  @change="autoSaven" placeholder="请输入活检数目" />
						</uni-forms-item>
					</uni-col>
					<uni-col :span="11">
						<uni-forms-item label="转移数目" name="qslbjSzkd">
							<uni-easyinput :disabled="isDisabled" v-model="shbl.qslbjSzkd" type="digit"  @change="autoSaven" placeholder="请输入转移数目" />
						</uni-forms-item>
					</uni-col>
				</uni-row>
				
				<uni-forms-item label="腋淋巴结清扫" name="ylbjqs">
					<uni-data-checkbox :disabled="isDisabled" v-model="shbl.ylbjqs" @change="ycxsChange($event,'ylbjqsSzcdShow',['ylbjqsSzcd','ylbjqsSzkd'])" :localdata="dictSf" />
				</uni-forms-item>
				<uni-row class="demo-uni-row" v-show="ylbjqsSzcdShow">
					<uni-col :span="11">
						<uni-forms-item label="清扫数目" name="ylbjqsSzcd">
							<uni-easyinput :disabled="isDisabled" v-model="shbl.ylbjqsSzcd" type="digit"  @change="autoSaven" placeholder="请输入清扫数目" />
						</uni-forms-item>
					</uni-col>
					<uni-col :span="11">
						<uni-forms-item label="转移数目" name="ylbjqsSzkd">
							<uni-easyinput :disabled="isDisabled" v-model="shbl.ylbjqsSzkd" type="digit"  @change="autoSaven" placeholder="请输入转移数目" />
						</uni-forms-item>
					</uni-col>
				</uni-row>
				
				<uni-forms-item label="是否远处转移" name="sfyczy">
					<uni-data-checkbox :disabled="isDisabled" v-model="shbl.sfyczy" @change="ycxsChange($event,'zybwShow',['zybw'])" :localdata="dictSf" />
				</uni-forms-item>
				<uni-forms-item label="转移部位" v-show="zybwShow" name="zybw">
					<uni-easyinput :disabled="isDisabled" v-model="shbl.zybw"  @change="autoSaven" placeholder="请输入转移部位" />
				</uni-forms-item>
				<uni-forms-item label="TNM分期" name="tnm">
					<uni-data-select
					      :disabled="isDisabled" v-model="shbl.tnm"
					      :localdata="tnmDictList"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="新辅助病理评估" name="xfzfj">
					<uni-data-select
					      :disabled="isDisabled" v-model="shbl.xfzfj"
					      :localdata="xfzfjDictList"></uni-data-select>
				</uni-forms-item>
				
				<uni-forms-item label="是否pCR" name="sfPcr">
					<uni-data-checkbox :disabled="isDisabled" v-model="shbl.sfPcr" @change="ycxsChange($event,'pcrJgShow',['pcrJg'])" :localdata="dictSf" />
				</uni-forms-item>
				<uni-forms-item label="pCR结果" v-show="pcrJgShow" name="pcrJg">
					<uni-data-select
					      :disabled="isDisabled" v-model="shbl.pcrJg"
					      :localdata="pcrDictList"></uni-data-select>
				</uni-forms-item>
				
				<uni-forms-item label="备注" name="remark">
					<uni-easyinput type="textarea" autoHeight :disabled="isDisabled" v-model="shbl.remark"  @change="autoSaven" placeholder="请输入备注"/>
				</uni-forms-item>
				<button type="primary" :disabled="isDisabled" @click="submit">保存</button>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	import storage from '@/utils/storage'
import { updateSsbl,getDicts,sfkybjData } from "@/api/trms/trms"
import { getSsbl } from "@/api/trms/query"
export default {
	data() {
		return {
			patientId: null,
			isDisabled: false,
			userId: null,
			qslbjhjjgShow: false,
			qslbjSzcdShow: false,
			ylbjqsSzcdShow: false,
			zybwShow: false,
			pcrJgShow: false,
			tnmDictList: [],
			fishDictList: [],
			fzfxDictList: [],
			xfzfjDictList: [],
			pcrDictList: [],
			her2DictList: [],
			// 表单数据
			shbl: {},
			rules: {
				admissionNumber: {
				  rules: [{
					required: true,
					errorMessage: '住院号不能为空'
				  }]
				}
			},
			dictSf: [
				{
				  text: '是',
				  value: 1
				}, {
				  text: '否',
				  value: 0
				}
			]
		}
	},
	onLoad: function(option) {
		this.getFishDict();
		this.getFzfxDict();
		this.getTnmDict();
		this.getXfzfjDict();
		this.getPcrDict();
		this.getHer2DictList();
		this.patientId = option.patientId;
		this.userId = option.userId;
		sfkybjData(this);
		console.log("进入术后病理页面后、参数：",this.patientId)
		if(this.patientId){
			// 查询详情
			this.getDataByPatientId();
		}
	},
	onReady() {
		this.$refs.form.setRules(this.rules)
	},
	methods: {
		/**
		 * 获取数据
		 */
		getDataByPatientId(){
			getSsbl(this.patientId).then(response => {
			  this.shbl = response.data;
			  this.shbl.blFish = this.shbl.blFish + '';
			  this.shbl.fzfx = this.shbl.fzfx + '';
			  this.shbl.tnm = this.shbl.tnm + '';
			  this.shbl.blHer = this.shbl.blHer + '';
			  this.shbl.xfzfj = this.shbl.xfzfj + '';
			  this.shbl.pcrJg = this.shbl.pcrJg + '';
			  this.showAndHide(response.data);
			});
		},
		getFishDict(){
			getDicts("trms_fish").then(response => {
				this.fishDictList = this.dictFormat(response.data);
			})
		},
		getFzfxDict(){
			getDicts("trms_fzfx").then(response => {
				this.fzfxDictList = this.dictFormat(response.data);
			})
		},
		getTnmDict(){
			getDicts("trms_tnm_bl").then(response => {
				this.tnmDictList = this.dictFormat(response.data);
			})
		},
		getXfzfjDict(){
			getDicts("trms_xfzfj").then(response => {
				this.xfzfjDictList = this.dictFormat(response.data);
			})
		},
		getPcrDict(){
			getDicts("trms_pcr").then(response => {
				this.pcrDictList = this.dictFormat(response.data);
			})
		},
		getHer2DictList(){
			getDicts("trms_her2").then(response => {
				this.her2DictList = this.dictFormat(response.data);
			})
		},
		/**
		 * 修改
		 */
		submit(){
			this.$refs.form.validate().then(res => {
				updateSsbl(this.shbl).then(response => {
				  if(response.code == 200){
					  this.$modal.msgSuccess("修改成功");
					  this.backWork();
					  return;
				  }
				  this.$modal.msgError(response.msg);
				});
			})
		},
		autoSaven(){
			this.$refs.form.validate().then(res => {
				updateSsbl(this.shbl).then(response => {
				  console.log("修改成功");
				});
			})
		},
		/**
		 * 回到工作页面
		 */
		backWork(){
			setTimeout(function (){
				uni.navigateBack({
					delta: 1
				});
			},500);
		},
		/**
		 * 给字典格式化成uniapp插件需要的格式
		 * @param {Object} list
		 */
		dictFormat(list){
			let newArr = [];
			if(!list){
				return newArr;
			}
			list.forEach(d=>{
				newArr.push({value: d.dictValue,text: d.dictLabel})
			})
			return newArr;
		},
		ycxsChange(e,show,valArr){
			const val = e.detail.value;
			this[show] = val == 1;
			let that = this;
			if(Number(val) == 0 ){
				// 清理值
				valArr.forEach(v => {
					that.shbl[v] = null;
				})
			}
		},
		/**
		 * 隐藏或者显示
		 * @param {Object} jbxx 
		 */
		showAndHide(jbxx){
			this.qslbjhjjgShow = jbxx.sfQslbjhj == 1;
			this.qslbjSzcdShow = jbxx.qslbj == 1;
			this.ylbjqsSzcdShow = jbxx.ylbjqs == 1;
			this.zybwShow = jbxx.sfyczy == 1;
			this.pcrJgShow = jbxx.sfPcr == 1;
		}
	}
}
</script>


<style lang="scss">
  page {
    background-color: #ffffff;
  }

  .example {
    padding: 15px;
    background-color: #fff;
  }

  .segmented-control {
    margin-bottom: 15px;
  }

  .button-group {
    margin-top: 15px;
    display: flex;
    justify-content: space-around;
  }

  .form-item {
    display: flex;
    align-items: center;
    flex: 1;
  }

  .button {
    display: flex;
    align-items: center;
    height: 35px;
    line-height: 35px;
    margin-left: 10px;
  }
  .wbkx{
  	  text-align: center;
  	  margin-top: 10px;
  }
</style>
